home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / getting there / Apps / AuthMan 1.0.8 / AuthMan DA / authLibrary.c < prev    next >
Text File  |  1994-05-12  |  12KB  |  445 lines

  1. /*
  2.  * Copyright (c) 1992-1994 Regents of The University of Michigan.
  3.  * All Rights Reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and
  6.  * its documentation for any purpose and without fee is hereby granted,
  7.  * provided that the above copyright notice appears in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation, and that the name of The University
  10.  * of Michigan not be used in advertising or publicity pertaining to
  11.  * distribution of the software without specific, written prior
  12.  * permission. This software is supplied as is without expressed or
  13.  * implied warranties of any kind.
  14.  *
  15.  *      Campus Computing Sites, Sales, and Service
  16.  *      The University of Michigan
  17.  *      c/o Robert John Churchill
  18.  *      535 W. William Street
  19.  *      Ann Arbor, Michigan
  20.  *      +1-313-936-2528
  21.  *      rjc@ccs.itd.umich.edu
  22.  */
  23.  
  24. #include <Devices.h>
  25. #include <Errors.h>
  26. #include <Files.h>
  27. #include <Types.h>
  28.  
  29. #ifdef    THINK_C
  30. #include <Pascal.h>
  31. #include <Think.h>
  32. #else
  33. What should we include for MPW?        // cause an error
  34. #endif    THINK_C
  35.  
  36. #include "authLibrary.h"
  37.  
  38.  
  39.  
  40. /*
  41.         Open Authentication Manager Driver
  42.         Note: if err, version undefined
  43. */
  44.  
  45. pascal OSErr
  46. openAuthMan(short *refNum,short *version)
  47. {
  48.     OSErr                err;
  49.     ParamBlockRec        paramBlock;
  50.  
  51. paramBlock.ioParam.ioCompletion=0L;
  52. paramBlock.ioParam.ioNamePtr=(void *)AUTHMAN_DRVR_NAME;
  53. paramBlock.ioParam.ioPermssn=fsCurPerm;
  54. if (!(err=PBOpen(¶mBlock,FALSE)))    {
  55.     *refNum=paramBlock.cntrlParam.ioCRefNum;
  56.     paramBlock.cntrlParam.csCode=GET_AUTH_VERSION;
  57.     if (!(err=PBControl(¶mBlock,FALSE)))    {
  58.         *version=paramBlock.cntrlParam.csParam[0];
  59.         }
  60.     }
  61. return(err);
  62. }
  63.  
  64.  
  65.  
  66. /*
  67.         Return Local Kerberos realm (Pascal string)
  68.         Note: if err, realmName is empty & realmType is UNKNONW_REALM_TYPE
  69. */
  70.  
  71. pascal OSErr
  72. getDefaultRealm(short refNum,Str255 *realmName,short *realmType)
  73. {
  74.     OSErr                err;
  75.     ParamBlockRec        paramBlock;
  76.  
  77. *(char *)realmName=0;
  78. *realmType=UNKNONW_REALM_TYPE;
  79. paramBlock.cntrlParam.ioCompletion=0L;
  80. paramBlock.cntrlParam.ioVRefNum=0;
  81. paramBlock.cntrlParam.ioCRefNum=refNum;
  82. paramBlock.cntrlParam.csCode=GET_LOCAL_REALM;
  83. *((Str255 **)¶mBlock.cntrlParam.csParam[0])=realmName;
  84. if (!(err=PBControl(¶mBlock,FALSE)))    {
  85.     *realmType=paramBlock.cntrlParam.csParam[2];
  86.     }
  87. return(err);
  88. }
  89.  
  90.  
  91.  
  92. /*
  93.         Get Authentication status (has a user authenticated?)
  94.         if zero, user hasn't authenticated;  if non-zero, user has
  95.         Note: if err, status undefined
  96. */
  97.  
  98. pascal OSErr
  99. getAuthenticationStatus(short refNum,short *status)
  100. {
  101.     OSErr                err;
  102.     ParamBlockRec        paramBlock;
  103.     short                retVal=FALSE;
  104.  
  105. paramBlock.cntrlParam.ioCompletion=0L;
  106. paramBlock.cntrlParam.ioVRefNum=0;
  107. paramBlock.cntrlParam.ioCRefNum=refNum;
  108. paramBlock.cntrlParam.csCode=GET_AUTH_STATUS;
  109. if (!(err=PBStatus(¶mBlock,FALSE)))    {
  110.     if (status)    *status=paramBlock.cntrlParam.csParam[0];
  111.     }
  112. return(err);
  113. }
  114.  
  115.  
  116.  
  117. /*
  118.         Return name user entered (Pascal string)
  119.         Note: if err, uniqName is empty
  120. */
  121.  
  122. pascal OSErr
  123. getUniqname(short refNum,Str255 *uniqName)
  124. {
  125.     OSErr                    err;
  126.     ParamBlockRec        paramBlock;
  127.  
  128. *(char *)uniqName=0;
  129. paramBlock.cntrlParam.ioCompletion=0L;
  130. paramBlock.cntrlParam.ioVRefNum=0;
  131. paramBlock.cntrlParam.ioCRefNum=refNum;
  132. paramBlock.cntrlParam.csCode=GET_AUTH_STATUS;
  133. if (!(err=PBStatus(¶mBlock,FALSE)))    {
  134.     if (paramBlock.cntrlParam.csParam[0])    {
  135.         paramBlock.cntrlParam.ioCompletion=0L;
  136.         paramBlock.cntrlParam.ioVRefNum=0;
  137.         paramBlock.cntrlParam.ioCRefNum=refNum;
  138.         paramBlock.cntrlParam.csCode=GET_UNIQNAME;
  139.         *((Str255 **)¶mBlock.cntrlParam.csParam[0])=uniqName;
  140.         err=PBControl(¶mBlock,FALSE);
  141.         }
  142.     else    {
  143.         err=statusErr;
  144.         }
  145.     }
  146. return(err);
  147. }
  148.  
  149.  
  150.  
  151. /*
  152.         Set default user name
  153. */
  154.  
  155. pascal OSErr
  156. setUniqname(short refNum,Str255 *uniqName)
  157. {
  158.     OSErr                    err;
  159.     ParamBlockRec        paramBlock;
  160.  
  161. paramBlock.cntrlParam.ioCompletion=0L;
  162. paramBlock.cntrlParam.ioVRefNum=0;
  163. paramBlock.cntrlParam.ioCRefNum=refNum;
  164. paramBlock.cntrlParam.csCode=SET_UNIQNAME;
  165. *((Str255 **)¶mBlock.cntrlParam.csParam[0])=uniqName;
  166. err=PBControl(¶mBlock,FALSE);
  167. return(err);
  168. }
  169.  
  170.  
  171.  
  172. /*
  173.         Tell driver to reload internal data such as realm names,
  174.         host names, force DNR lookups to get IP numbers, etc...
  175.         Note: not currently implemented
  176. */
  177.  
  178. pascal OSErr
  179. reloadDrvrInfo(short refNum)
  180. {
  181.     OSErr                err;
  182.     ParamBlockRec        paramBlock;
  183.  
  184. paramBlock.cntrlParam.ioCompletion=0L;
  185. paramBlock.cntrlParam.ioVRefNum=0;
  186. paramBlock.cntrlParam.ioCRefNum=refNum;
  187. paramBlock.cntrlParam.csCode=RELOAD_INFO;
  188. err=PBControl(¶mBlock,FALSE);
  189. return(err);
  190. }
  191.  
  192.  
  193.  
  194. /*
  195.         Get Kerberos v4 ticket
  196.         if promptUserFlag is non-zero, user can be prompted
  197.         lifetimeInSecs is the # of secs ticket is valid (or INFINITE_LIFETIME)
  198.         Note: if err, ticketStorage and ticketLen are undefined
  199. */
  200.  
  201. pascal OSErr
  202. getV4Ticket(short refNum,void *ticketStorage,short *ticketLen,Str255 *sName,    \
  203.     Str255 *sInstance,Str255 *sRealm,long lifetimeInSecs,short promptUserFlag)
  204. {
  205.     OSErr                err;
  206.     ParamBlockRec        paramBlock;
  207.  
  208. if (sName)        PtoCstr((void *)sName);
  209. if (sInstance)    PtoCstr((void *)sInstance);
  210. if (sRealm)        PtoCstr((void *)sRealm);
  211.  
  212. paramBlock.cntrlParam.ioCompletion=0L;
  213. paramBlock.cntrlParam.ioVRefNum=0;
  214. paramBlock.cntrlParam.ioCRefNum=refNum;
  215. paramBlock.cntrlParam.csCode=GET_V4_TICKET;
  216. *((char **)¶mBlock.cntrlParam.csParam[0])=(void *)sName;
  217. *((char **)¶mBlock.cntrlParam.csParam[2])=(void *)sInstance;
  218. *((char **)¶mBlock.cntrlParam.csParam[4])=(void *)sRealm;
  219. *((long *)¶mBlock.cntrlParam.csParam[6])=lifetimeInSecs;
  220. paramBlock.cntrlParam.csParam[8]=promptUserFlag;
  221. *((char **)¶mBlock.cntrlParam.csParam[9])=ticketStorage;
  222. if (!(err=PBControl(¶mBlock,FALSE)))    {
  223.     *ticketLen=paramBlock.cntrlParam.csParam[0];
  224.     }
  225.  
  226. if (sName)        CtoPstr((void *)sName);
  227. if (sInstance)    CtoPstr((void *)sInstance);
  228. if (sRealm)        CtoPstr((void *)sRealm);
  229.  
  230. return(err);
  231. }
  232.  
  233.  
  234.  
  235. /*
  236.         Expire Kerberos v4 ticket(s)
  237.         passing NULL instead of a string acts like a wildcard
  238.             ex: sName=NULL, sInstance=NULL, sRealm="\pUMICH.EDU"
  239.                 deletes all UMICH.EDU realm tickets
  240.         Note: err=paramErr if any tickets exist in ticket queue and
  241.               parameters passed in matched none of them
  242. */
  243.  
  244. pascal OSErr
  245. expireV4Ticket(short refNum,Str255 *sName,Str255 *sInstance,Str255 *sRealm)
  246. {
  247.     OSErr                err;
  248.     ParamBlockRec        paramBlock;
  249.  
  250. if (sName)        PtoCstr((void *)sName);
  251. if (sInstance)    PtoCstr((void *)sInstance);
  252. if (sRealm)        PtoCstr((void *)sRealm);
  253.  
  254. paramBlock.cntrlParam.ioCompletion=0L;
  255. paramBlock.cntrlParam.ioVRefNum=0;
  256. paramBlock.cntrlParam.ioCRefNum=refNum;
  257. paramBlock.cntrlParam.csCode=EXPIRE_V4_TICKET;
  258. *((char **)¶mBlock.cntrlParam.csParam[0])=(void *)sName;
  259. *((char **)¶mBlock.cntrlParam.csParam[2])=(void *)sInstance;
  260. *((char **)¶mBlock.cntrlParam.csParam[4])=(void *)sRealm;
  261. err=PBControl(¶mBlock,FALSE);
  262.  
  263. if (sName)        CtoPstr((void *)sName);
  264. if (sInstance)    CtoPstr((void *)sInstance);
  265. if (sRealm)        CtoPstr((void *)sRealm);
  266.  
  267. return(err);
  268. }
  269.  
  270.  
  271.  
  272. /*
  273.         get Kerberos v4 ticket info from cache
  274.         ticketNum range: 0 to n-1  (given n tickets)
  275.         returns paramErr if ticketNum out of range
  276.         Note: if err, strings and dates are undefined
  277. */
  278.  
  279. pascal OSErr
  280. getV4TicketNinfo(short refNum,short ticketNum,_V4ticketInfo *theTicketInfo)
  281. {
  282.     OSErr                err;
  283.     ParamBlockRec        paramBlock;
  284.  
  285. paramBlock.cntrlParam.ioCompletion=0L;
  286. paramBlock.cntrlParam.ioVRefNum=0;
  287. paramBlock.cntrlParam.ioCRefNum=refNum;
  288. paramBlock.cntrlParam.csCode=GET_V4_TICKET_N_INFO;
  289. paramBlock.cntrlParam.csParam[0]=ticketNum;
  290. *((_V4ticketInfo **)¶mBlock.cntrlParam.csParam[1])=(void *)theTicketInfo;
  291. err=PBControl(¶mBlock,FALSE);
  292.  
  293. CtoPstr((void *)theTicketInfo->sName);
  294. CtoPstr((void *)theTicketInfo->sInstance);
  295. CtoPstr((void *)theTicketInfo->sRealm);
  296. CtoPstr((void *)theTicketInfo->pName);
  297. CtoPstr((void *)theTicketInfo->pInstance);
  298. CtoPstr((void *)theTicketInfo->pRealm);
  299.  
  300. return(err);
  301. }
  302.  
  303.  
  304.  
  305. /*
  306.         get Kerberos realm info from cache
  307.         realm range: 0 to n-1 (given n realms)
  308.         returns paramErr if realmNum out of range
  309.         Note: if err, realmName, AFSFlag, and numHosts are undefined
  310. */
  311.  
  312. pascal OSErr
  313. getRealmNinfo(short refNum,short realmNum,Str255 *realmName,short *AFSflag,short *numHosts)
  314. {
  315.     OSErr                err;
  316.     ParamBlockRec        paramBlock;
  317.  
  318. paramBlock.cntrlParam.ioCompletion=0L;
  319. paramBlock.cntrlParam.ioVRefNum=0;
  320. paramBlock.cntrlParam.ioCRefNum=refNum;
  321. paramBlock.cntrlParam.csCode=GET_REALM_N_INFO;
  322. paramBlock.cntrlParam.csParam[0]=realmNum;
  323. *((char **)&(paramBlock.cntrlParam.csParam[1]))=(char *)realmName;
  324. if (!(err=PBControl(¶mBlock,FALSE)))    {
  325.     if (realmName)    CtoPstr((void *)realmName);
  326.     if (AFSflag)    *AFSflag=paramBlock.cntrlParam.csParam[3];
  327.     if (numHosts)    *numHosts=paramBlock.cntrlParam.csParam[4];
  328.     }
  329. return(err);
  330. }
  331.  
  332.  
  333.  
  334. /*
  335.         get host service for a given Kerberos realm
  336.         host range: 0 to n-1 (given n hosts for given realm)
  337.         returns paramErr if index out of range
  338.         Note: if err, hostName is undefined
  339. */
  340.  
  341. pascal OSErr
  342. getRealmHostNinfo(short refNum,short realmNum,short hostNum,Str255 *hostName,short *portNum)
  343. {
  344.     OSErr                err;
  345.     ParamBlockRec        paramBlock;
  346.  
  347. paramBlock.cntrlParam.ioCompletion=0L;
  348. paramBlock.cntrlParam.ioVRefNum=0;
  349. paramBlock.cntrlParam.ioCRefNum=refNum;
  350. paramBlock.cntrlParam.csCode=GET_REALM_HOST_N_INFO;
  351. paramBlock.cntrlParam.csParam[0]=realmNum;
  352. paramBlock.cntrlParam.csParam[1]=hostNum;
  353. *((char **)&(paramBlock.cntrlParam.csParam[2]))=(char *)hostName;
  354. if (!(err=PBControl(¶mBlock,FALSE)))    {
  355.     if (hostName)    CtoPstr((void *)hostName);
  356.     if (portNum)    *portNum=paramBlock.cntrlParam.csParam[4];
  357.     }
  358. return(err);
  359. }
  360.  
  361.  
  362.  
  363. /*
  364.         Encrypt or Decrypt blocks of memory w/DES
  365.         
  366.         when operation is DES_PCBC-based, buffer data and bufferLen must be a 8-byte multiple
  367.         when operation is  DES_ECB-based, buffer data and bufferLen must be 8 bytes
  368. */
  369.  
  370. pascal OSErr
  371. doDES(short refNum,short operation,void *sessionKey,void *buffer,long bufferLen)
  372. {
  373.     OSErr                err;
  374.     ParamBlockRec        paramBlock;
  375.  
  376. paramBlock.cntrlParam.ioCompletion=0L;
  377. paramBlock.cntrlParam.ioVRefNum=0;
  378. paramBlock.cntrlParam.ioCRefNum=refNum;
  379. paramBlock.cntrlParam.csCode=DES_FUNCTIONS;
  380. paramBlock.cntrlParam.csParam[0]=operation;
  381. *((char **)&(paramBlock.cntrlParam.csParam[1]))=sessionKey;
  382. *((char **)&(paramBlock.cntrlParam.csParam[3]))=buffer;
  383. *((long *)&(paramBlock.cntrlParam.csParam[5]))=bufferLen;
  384. err=PBControl(¶mBlock,FALSE);
  385. return(err);
  386. }
  387.  
  388.  
  389.  
  390. /*
  391.         Set new Password for user
  392.         Note: pName/pInstance/pRealm parameters are suggested
  393.                 default values for when the password changing
  394.                 dialog comes up
  395. */
  396.  
  397. pascal OSErr
  398. setV4Password(short refNum,Str255 *pName,Str255 *pInstance,Str255 *pRealm)
  399. {
  400.     OSErr                err;
  401.     ParamBlockRec        paramBlock;
  402.  
  403. paramBlock.cntrlParam.ioCompletion=0L;
  404. paramBlock.cntrlParam.ioVRefNum=0;
  405. paramBlock.cntrlParam.ioCRefNum=refNum;
  406. paramBlock.cntrlParam.csCode=SET_V4_PASSWORD;
  407. *((char **)&(paramBlock.cntrlParam.csParam[0]))=(char *)pName;
  408. *((char **)&(paramBlock.cntrlParam.csParam[2]))=(char *)pInstance;
  409. *((char **)&(paramBlock.cntrlParam.csParam[4]))=(char *)pRealm;
  410. err=PBControl(¶mBlock,FALSE);
  411. return(err);
  412. }
  413.  
  414.  
  415.  
  416. /*
  417.         Register/Deregister for callback messages from AuthMan
  418.         Note: if used by an application, the callback must be unregistered
  419.                   before the application exits
  420.               when callbackRtn is actually called, it may not in turn make
  421.                   calls to AuthMan as AuthMan is "busy" and a LOCK condition
  422.                   would occur
  423.               the callbackRtn must be in a locked, non-purgeable segment of code
  424.               the callbackRtn should always return  noErr  unless indicated as
  425.                   being allowed for a given message
  426. */
  427.  
  428. pascal OSErr
  429. doMsgCallback(short refNum,short callbackOperation,doAuthMsgCallbackProc callbackRtn,long callbackMiscData,long userData)
  430. {
  431.     OSErr                err;
  432.     ParamBlockRec        paramBlock;
  433.  
  434. paramBlock.cntrlParam.ioCompletion=0L;
  435. paramBlock.cntrlParam.ioVRefNum=0;
  436. paramBlock.cntrlParam.ioCRefNum=refNum;
  437. paramBlock.cntrlParam.csCode=AUTH_MSG_CALLBACK;
  438. paramBlock.cntrlParam.csParam[0]=callbackOperation;
  439. *((doAuthMsgCallbackProc **)&(paramBlock.cntrlParam.csParam[1]))=callbackRtn;
  440. *((long *)&(paramBlock.cntrlParam.csParam[3]))=callbackMiscData;
  441. *((long *)&(paramBlock.cntrlParam.csParam[5]))=userData;
  442. err=PBControl(¶mBlock,FALSE);
  443. return(err);
  444. }
  445.